/************************************************************************
                        DataVerificator.h.cpp - Copyright asaf
*/
#include "DataVerificator.h"
#include "..\Shered\GlobalFunctions.h"
// ctor/dtor
DataVerificator::DataVerificator ( ) {}

DataVerificator::~DataVerificator ( ) { }

bool  DataVerificator::validateRequest (const Request &request) {
	RequestData *requestdata;
	switch(request.getRequestType())
	{
	case LOGIN:
		requestdata=(RequestData *)&request;
		if(requestdata->getParameter("ID")=="")return  false;
		return true;
	case LOGOUT:
		requestdata=(RequestData *)&request;
		if(requestdata->getParameter("ID")=="")return  false;
		return true;
	case ADD_PERSON:
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("ID")=="")||
			(requestdata->getParameter("FirstName")=="")||
			(requestdata->getParameter("LastName")=="")||
			(requestdata->getParameter("Semester")=="")||
			(requestdata->getParameter("Address")=="")||
			(requestdata->getParameter("BirthDay")=="")||
			(requestdata->getParameter("BirthMonth")=="")||
			(requestdata->getParameter("BirthYear")=="")||
			(stringToInt(requestdata->getParameter("BirthYear"))<0)||
			(!intBetween(stringToInt(requestdata->getParameter("BirthMonth")),0,13))||
			(!intBetween(stringToInt(requestdata->getParameter("BirthDay")),0,32))||
			(!intBetween(stringToInt(requestdata->getParameter("Semester")),0,7))||
			(USER_TYPE_TO_INT(requestdata->getParameter("Type"))==TYPE_NONE)||
			(USER_PERMISSION_TO_INT(requestdata->getParameter("Permission"))==NONE))
			return  false;
		return true;
	case ADD_COURSE:
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("ID")=="")||
			(requestdata->getParameter("Semester")=="")||
			(!intBetween(stringToInt(requestdata->getParameter("Semester")),0,7))||
	       	(requestdata->getParameter("CourseName")=="")||
			(requestdata->getParameter("Start_Hour")=="")||
			(requestdata->getParameter("End_Hour")=="")||
			(requestdata->getParameter("Weekday")=="")||
			(requestdata->getParameter("Start_Hour2")=="")||
			(requestdata->getParameter("End_Hour2")=="")||
			(requestdata->getParameter("Weekday2")=="")||
			(requestdata->getParameter("LectID")=="")||
			(requestdata->getParameter("LectID2")=="")||
			(requestdata->getParameter("MaxAttendants")=="")||
			(requestdata->getParameter("MaxAttendants2")=="")||
			(stringToInt(requestdata->getParameter("Start_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("End_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("Weekday"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("Start_Hour2"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("End_Hour2"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("Weekday2"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("MaxAttendants"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("MaxAttendants2"))==stringToInt_ErrCode)||
			(!intBetween(stringToInt(requestdata->getParameter("Start_Hour")),-1,stringToInt(requestdata->getParameter("End_Hour"))))||
			(!intBetween(stringToInt(requestdata->getParameter("End_Hour")),stringToInt(requestdata->getParameter("Start_Hour")),25))||
			(!intBetween(stringToInt(requestdata->getParameter("Weekday")),0,8))||
			(!intBetween(stringToInt(requestdata->getParameter("Start_Hour2")),-1,stringToInt(requestdata->getParameter("End_Hour2"))))||
			(!intBetween(stringToInt(requestdata->getParameter("End_Hour2")),stringToInt(requestdata->getParameter("Start_Hour2")),25))||
			(!intBetween(stringToInt(requestdata->getParameter("Weekday2")),0,8))||
			((requestdata->getParameter("Start_Hour")==requestdata->getParameter("Start_Hour2"))&&
			(requestdata->getParameter("End_Hour")==requestdata->getParameter("End_Hour2"))&&
			(requestdata->getParameter("Weekday")==requestdata->getParameter("Weekday2"))&&
			(requestdata->getParameter("LectID")==requestdata->getParameter("LectID2"))))
			return  false;
		return true;
	case DELETE_PERSON:
		requestdata=(RequestData *)&request;
		if(requestdata->getParameter("ID")=="")return  false;
		return true;
	case DELETE_COURSE:
		requestdata=(RequestData *)&request;
		if(requestdata->getParameter("ID")=="")return  false;
		return true;
	case EDIT_PERSON:
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("ID")=="")||
			(requestdata->getParameter("FirstName")=="")||
			(requestdata->getParameter("LastName")=="")||
			(requestdata->getParameter("Semester")=="")||
			(!intBetween(stringToInt(requestdata->getParameter("Semester")),0,7))||
			(USER_TYPE_TO_INT(requestdata->getParameter("Type"))==TYPE_NONE)||
			(USER_PERMISSION_TO_INT(requestdata->getParameter("Permission"))==NONE))
			return  false;
		return true;
	case REGISTER_STUDENT_COURSE:
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("StudentID")=="")||
	       	(requestdata->getParameter("CourseID")=="")||
			(requestdata->getParameter("LectID")=="")||
			(requestdata->getParameter("Start_Hour")=="")||
			(requestdata->getParameter("End_Hour")=="")||
			(requestdata->getParameter("Semester")=="")||
			(requestdata->getParameter("Weekday")=="")||
			(requestdata->getParameter("Completed")=="")||
			(stringToInt(requestdata->getParameter("Start_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("End_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("Weekday"))==stringToInt_ErrCode)||
			(!intBetween(stringToInt(requestdata->getParameter("Start_Hour")),-1,stringToInt(requestdata->getParameter("End_Hour")))||
			(!intBetween(stringToInt(requestdata->getParameter("End_Hour")),stringToInt(requestdata->getParameter("Start_Hour")),25))||
			(!intBetween(stringToInt(requestdata->getParameter("Semester")),0,7))||
			(!intBetween(stringToInt(requestdata->getParameter("Completed")),-1,2))||
			(!intBetween(stringToInt(requestdata->getParameter("Weekday")),0,8))))
			return  false;
		return true;

	case SET_STUDENT_COURSE_COMPLETED:
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("StudentID")=="")||
	       	(requestdata->getParameter("CourseID")=="")||
			(requestdata->getParameter("LectID")=="")||
			(requestdata->getParameter("Start_Hour")=="")||
			(requestdata->getParameter("End_Hour")=="")||
			(requestdata->getParameter("Semester")=="")||
			(requestdata->getParameter("Weekday")=="")||
			(requestdata->getParameter("Completed")=="")||
			(stringToInt(requestdata->getParameter("Start_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("End_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("Weekday"))==stringToInt_ErrCode)||
			(!intBetween(stringToInt(requestdata->getParameter("Start_Hour")),-1,stringToInt(requestdata->getParameter("End_Hour")))||
			(!intBetween(stringToInt(requestdata->getParameter("End_Hour")),stringToInt(requestdata->getParameter("Start_Hour")),25))||
			(!intBetween(stringToInt(requestdata->getParameter("Semester")),0,7))||
			(!intBetween(stringToInt(requestdata->getParameter("Completed")),-1,2))||
			(!intBetween(stringToInt(requestdata->getParameter("Weekday")),0,8))))
			return  false;
		return true;
	case ASSIGN_COURSE_LECTURER:
		//Start_Hour,End_Hour,Semester,Weekday (all int)
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("LectID")=="")||
	       	(requestdata->getParameter("CourseID")=="")||
			(requestdata->getParameter("Start_Hour")=="")||
			(requestdata->getParameter("End_Hour")=="")||
			(requestdata->getParameter("Semester")=="")||
			(requestdata->getParameter("Weekday")=="")||
			(stringToInt(requestdata->getParameter("Start_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("End_Hour"))==stringToInt_ErrCode)||
			(stringToInt(requestdata->getParameter("Weekday"))==stringToInt_ErrCode)||
			(!intBetween(stringToInt(requestdata->getParameter("Start_Hour")),-1,stringToInt(requestdata->getParameter("End_Hour")))||
			(!intBetween(stringToInt(requestdata->getParameter("End_Hour")),stringToInt(requestdata->getParameter("Start_Hour")),24))||
			(!intBetween(stringToInt(requestdata->getParameter("Semester")),0,7))||
			(!intBetween(stringToInt(requestdata->getParameter("Weekday")),0,8))))
			return  false;
		return true;

	case GET_ALL_COURSE:
		return true;
	case GET_COURSE_DATA:
		requestdata=(RequestData *)&request;
		if(requestdata->getParameter("ID")=="")return  false;
		return true;
	case GET_PERSON_DATA:
		requestdata=(RequestData *)&request;
		if(requestdata->getParameter("ID")=="")return  false;
		return true;
	case ADD_COURSE_PREREQUISITE:
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("CourseID")=="")||
	       	(requestdata->getParameter("PreRequisitCourseID")==""))
			return false;
		return true;
	case GET_COURSES_FOR_SEMESTER:
		requestdata=(RequestData *)&request;
		if((requestdata->getParameter("Semester")=="")||
			(!intBetween(stringToInt(requestdata->getParameter("Semester")),0,7)))return  false;
		return true;
	default:
		return  false;
		break;
	}
}


